//package com.demo.handler;
//
//import com.alibaba.excel.metadata.CellData;
//import com.alibaba.excel.metadata.Head;
//import com.alibaba.excel.util.StyleUtil;
//import com.alibaba.excel.write.handler.CellWriteHandler;
//import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
//import com.alibaba.excel.write.metadata.holder.WriteTableHolder;
//import com.alibaba.excel.write.metadata.style.WriteCellStyle;
//import com.alibaba.excel.write.metadata.style.WriteFont;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.commons.collections4.CollectionUtils;
//import org.apache.poi.ss.usermodel.Cell;
//import org.apache.poi.ss.usermodel.CellStyle;
//import org.apache.poi.ss.usermodel.Comment;
//import org.apache.poi.ss.usermodel.Drawing;
//import org.apache.poi.ss.usermodel.IndexedColors;
//import org.apache.poi.ss.usermodel.Row;
//import org.apache.poi.ss.usermodel.Sheet;
//import org.apache.poi.ss.usermodel.Workbook;
//import org.apache.poi.xssf.usermodel.XSSFClientAnchor;
//import org.apache.poi.xssf.usermodel.XSSFRichTextString;
//
//import java.util.HashMap;
//import java.util.List;
//
///**
// * @author wangfengchen
// */
//@Slf4j
//public class TitleHandler implements CellWriteHandler {
//
//  //操作列
//  private List<Integer> columnIndex;
//  //颜色
//  private Short colorIndex;
//  // 批注<列的下标,批注内容>
//  private HashMap<Integer,String> annotationsMap;
//
//  public TitleHandler(List<Integer> columnIndex, Short colorIndex,
//      HashMap<Integer,String> annotationsMap) {
//    this.columnIndex = columnIndex;
//    this.colorIndex = colorIndex;
//    this.annotationsMap = annotationsMap;
//  }
//
//  public TitleHandler(List<Integer> columnIndex, Short colorIndex) {
//    this.columnIndex = columnIndex;
//    this.colorIndex = colorIndex;
//  }
//
//  @Override
//  public void beforeCellCreate(WriteSheetHolder writeSheetHolder,
//      WriteTableHolder writeTableHolder, Row row, Head head,
//      Integer columnIndex, Integer relativeRowIndex, Boolean isHead) {
//  }
//
//  @Override
//  public void afterCellCreate(WriteSheetHolder writeSheetHolder,
//      WriteTableHolder writeTableHolder, Cell cell, Head head,
//      Integer relativeRowIndex, Boolean isHead) {
//  }
//
//  @Override
//  public void afterCellDataConverted(WriteSheetHolder writeSheetHolder,
//      WriteTableHolder writeTableHolder, CellData cellData, Cell cell,
//      Head head, Integer integer, Boolean aBoolean) {
//
//  }
//
//  @Override
//  public void afterCellDispose(WriteSheetHolder writeSheetHolder,
//      WriteTableHolder writeTableHolder, List<CellData> cellDataList, Cell cell,
//      Head head, Integer relativeRowIndex, Boolean isHead) {
//    if (isHead) {
//      // 设置列宽
//      Sheet sheet = writeSheetHolder.getSheet();
//      sheet.setColumnWidth(cell.getColumnIndex(), 14 * 256);
//      writeSheetHolder.getSheet().getRow(0).setHeight((short) (1.8 * 256));
//      Workbook workbook = writeSheetHolder.getSheet().getWorkbook();
//      Drawing drawing = sheet.createDrawingPatriarch();
//
//      // 设置标题字体样式
//      WriteCellStyle headWriteCellStyle = new WriteCellStyle();
//      WriteFont headWriteFont = new WriteFont();
//      headWriteFont.setFontName("宋体");
//      headWriteFont.setFontHeightInPoints((short) 14);
//      headWriteFont.setBold(true);
//      if (CollectionUtils.isNotEmpty(columnIndex) && columnIndex.contains(
//          cell.getColumnIndex())) {
//        // 设置字体颜色
//        headWriteFont.setColor(colorIndex);
//      }
//      headWriteCellStyle.setWriteFont(headWriteFont);
//      // 设置背景颜色
//      headWriteCellStyle.setFillForegroundColor(
//          IndexedColors.GREY_25_PERCENT.getIndex());
//      CellStyle cellStyle = StyleUtil.buildHeadCellStyle(workbook,
//          headWriteCellStyle);
//      cell.setCellStyle(cellStyle);
//
//      if (null != annotationsMap && annotationsMap.containsKey(
//          cell.getColumnIndex())) {
//        // 批注内容
//        String context = annotationsMap.get(cell.getColumnIndex());
//        // 创建绘图对象，XSSFClientAnchor的参数说明：
//        // dx1：第1个单元格中x轴的偏移量
//        // dy1：第1个单元格中y轴的偏移量
//        // dx2：第2个单元格中x轴的偏移量
//        // dy2：第2个单元格中y轴的偏移量
//        // col1：第1个单元格的列号
//        // row1：第1个单元格的行号
//        // col2：第2个单元格的列号
//        // row2：第2个单元格的行号
//        Comment comment = drawing.createCellComment(
//            new XSSFClientAnchor(0, 0, 0, 0, (short) cell.getColumnIndex(), 0,
//                (short) 5, 5));
//        comment.setString(new XSSFRichTextString(context));
//        cell.setCellComment(comment);
//      }
//    }
//  }
//}